<template>
    <view>
        <div style="margin-bottom: 60px;">
            <u-cell-item v-for="(item, index) in tbShippingAddressList" :key="item.id" :arrow="false" use-label-slot
                         @click="selectTbShippingAddress(item, index)">
                <view slot="title" style="display: flex; font-weight: bold; font-size: 16px;">
                    <div style="margin-right: 25px;">
                        {{ item.consignee }}
                    </div>
                    <div style="margin-right: 25px;">
                        {{ item.phone }}
                    </div>
                    <div>
                        <u-tag v-if="item.isDefault" text="默认" type="error" shape="circle" mode="dark"/>
                    </div>
                </view>
                <view slot="label">
                    {{item.provinceName + item.cityName + item.areaName + item.address}}
                </view>
                <u-icon slot="right-icon" size="40" name="arrow-right" style="padding-left: 20px;"></u-icon>
            </u-cell-item>
        </div>

        <div v-if="!tbShippingAddressList.length">
            <u-empty text="没有添加收货地址" mode="address"></u-empty>
        </div>

        <div class="custom-bottom-button" @tap="navigateTo('/pages/sub/sub1-tabs/tabs/person/shipping-address/index')">
            <label>管理收货地址</label>
        </div>
    </view>
</template>

<script>

    import {TbShippingAddressService} from "@/dev/services/tb-shipping-address.service";

    export default {
        data() {
            return {
                tbShippingAddressList: []
            };
        },
        onShow() {
            this.findTbShippingAddressList()
        },
        methods: {
            findTbShippingAddressList() {
                new TbShippingAddressService().findTbShippingAddressList({
                    communityId: this.globalVariable.userInfo.tbCommunity.id,
                    userId: this.globalVariable.userInfo.id,
                    orderBy: 'is_default desc, create_time desc'
                }).then(result => {
                    this.tbShippingAddressList = result
                })
            },
            selectTbShippingAddress(item, index) {
                // let app = getApp()
                Object.assign(this.objParams, item);
                uni.navigateBack({delta: 1}) // 返回上一级页面。
            },
        }
    };
</script>

<style lang="scss" scoped>
</style>
